package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;

public class BibliotecaApp {

    private BufferedReader inputDataBuffer;
    private Printer printer;
    //public HashMap<String, Boolean> books = new HashMap<String, Boolean>();
    private BookLibrary bookLibrary;

    public BibliotecaApp(Printer startUp, BufferedReader inputDataBuffer, BookLibrary bookLibrary) {
        this.printer = startUp;
        this.inputDataBuffer = inputDataBuffer;
        this.bookLibrary = bookLibrary;
    }

    public String readUserInput() throws IOException {
        String input = inputDataBuffer.readLine();
        return input;
    }

    public void populateLibrary() {
        bookLibrary.addBook("Harry");
        bookLibrary.addBook("The Pearl");
        bookLibrary.addBook("Of Mice and Men");

    }

    public void run() throws IOException {

        printer.welcome();
        printer.menuOptions();
        this.runThroughMenu(readUserInput());
    }

    public void runThroughMenu(String input) throws IOException {

//       HashMap<String,MenuOptions> options = new HashMap<String,MenuOptions>();
//       options.put("1",new PrintBooks(bookLibrary));
//       options.put("2",new Reserve(bookLibrary,printer,this));
//       options.put("3",new Error(printer));
//        options.put("4",new Error(printer));
//
//        options.get(input);


        if (input.equals("1")) {
            new PrintBooks(bookLibrary);
        } else if (input.equals("2")) {
            new Reserve(bookLibrary, printer, this);
        } else if (input.equals("3")) {
            askLibrarian();
        } else new Error(printer);
    }

    private void askLibrarian() {
        printer.askLibrarianMessage();
    }


}
